#个人银行账户管理系统

#定义用于存放个人账户的列表变量
userInfoList=[
    {"username":"Wang Lei","age":20,'userid':"001","balance":1200,"password":"123"},
    {"username": "Li Wen", "age": 30, 'userid': "002", "balance": 10000,"password":"123"},
    {"username": "Wang Hu", "age": 23, 'userid': "003", "balance": 1000,"password":"123"},
    {"username": "Yu Mei", "age": 18, 'userid': "004", "balance": 800,"password":"123"},
]

def showUserAccountInfo(userId):
    for user in userInfoList:
        if(user["userid"]==userId):
            print("=" * 20, "用户信息查询结果", "=" * 21)
            print("|{0:<10}|{1:<10}|{2:<10}|".format("用户编号","姓名",  "账户余额"))
            print("|{0:<10}|{1:<10}|{2:<10}|".format( user["userid"], user["username"],user["balance"]))
            print("")

def drawMoney(user,amount):
    if int(user["balance"])< int(amount):
        print("余额不足！")
        return
    else:
        user["balance"]=str(int(user["balance"])-int(amount))
        updateUserbalance(userInfoList,user)
        print("取款成功")
        print("您的当前余额是：", user['balance'])
        return

def updateUserbalance(userInfoList,user):
        index = 0
        for u in userInfoList:
            if (u["userid"] == user["userid"]):
                    userInfoList[index]['balance'] = user['balance']
                    return
            index += 1
        print("用户信息不正确")
        print("")
        print("")


def saveMoney(user,amount):
    user["balance"] = str(int(user["balance"]) + int(amount))
    updateUserbalance(userInfoList, user)
    print("存款成功")
    print("您的当前余额是：", user['balance'])

while True:
    #输出登入页面
    print("="*20,"银行个人账户查询系统","="*20)
    print("")
    print("{0:<25}|{1:<25}".format("1，登入", "2，退出"))
    yourInput = input("请输入你的操作选项:")
    if yourInput == '1':
        print("-"*20,"请输入登入信息","-"*20)
        isLogin=False
        name =input("请输入用户名:")
        password =input("请输入密码:")
        for user in userInfoList:
            if user["username"] == name and user["password"] == password:
                print("")
                print("登入成功", "欢迎您", name)
                isLogin = True
                while True:
                    print("=" * 20, "银行个人账户管理系统", "=" * 20)
                    print("|{0:<25}|{1:<25}".format("1，查询", "2，取钱"))
                    print("|{0:<25}|{1:<25}".format("3，存钱", "4，退出"))
                    print("=" * 20, "选择你的操作序列号", "=" * 21)
                    yourChose = input("请输入你的操作选项:")
                    if yourChose == '1':
                        print("")
                        showUserAccountInfo(user["userid"])
                    elif yourChose == '2':
                        print("您的当前余额是：", user['balance'])
                        amount = input("请输入你要取款金额：")
                        drawMoney(user, amount)

                    elif yourChose == '3':
                        print("您的当前余额是：", user['balance'])
                        amount = input("请输入你要存款金额：")
                        saveMoney(user, amount)
                    elif yourChose == '4':
                        print("=" * 20, "再见", "=" * 33)
                        print("")
                        print("")

                        break
                    elif yourChose == '':
                        print("请输入操作序列号")
                        print("")
                    else:
                        print("没有这个选项，重新选择")
                        print("")

        if not isLogin:
            print("")
            print("用户信息错误，重新输入")
            print("")
    else:
        print("=" * 20, "再见", "=" * 33)
        print("")
        print("")
        break








